const { DB } = require('./sqlite3');

const PriceDao = {
    logPrice(price, callback) {
        DB.run(`INSERT INTO price_log (price , c_time) VALUES ( ${price} , ${Date.now()} )`);
        typeof callback === "function" && callback();
    },
    savePriceStack(priceStack, callback) {
        DB.run("INSERT INTO price_log (price , c_time) VALUES ", priceStack.map(e => `(${e.price},${e.c_time})`).join(','));
        typeof callback === "function" && callback();
    },
    getPriceBetween(start, end, callback) {
        db.all(`SELECT price,c_time FROM mouse_pos WHERE c_time BETWEEN ${start} AND ${end} `, (err, rows) => {
            typeof callback === "function" && callback(rows);
        });
    },
    clearAllPrice(callback){
        DB.run('DELETE FROM price_log');
        typeof callback === "function" && callback();
    }
}

module.exports.PriceDao = PriceDao;